Mathematical Documentation
The dynamics, controllers, and environments of this simulator, stated precisely and self-contained: every model is derived from first principles for planar rigid-link walkers with rigid inelastic ground contact, and every equation documented here is what the code computes. Where an implementation simplifies a published theory, the simplification is stated.
1 Model class and notation
Every robot is a planar tree of rigid links pinned to the ground at a stance contact. Coordinates are absolute link angles \(q \in \mathbb{R}^N\) measured from the ground normal in a tilted frame: the ground is the \(x\) axis, gravity is rotated by the slope \(\alpha\), and the unit vector along a link is \(u(\theta) = [\sin\theta,\ \cos\theta]^{\mathsf T}\), so \(\theta > 0\) tilts the top of the link toward \(+x\). Each lumped mass \(k\) sits at
\[ c_k(q) \;=\; p_{\mathrm{base}} \;+\; \sum_{j=1}^{N} A_{kj}\, u(q_j), \]where the constant matrix \(A\) encodes the kinematic tree: entry \(A_{kj}\) is the length of link \(j\) lying between the base and mass \(k\), signed negative for links traversed tip to root (the swing leg). This single matrix generates the entire model: define
\[ B^c_{ij} \;=\; \sum_k m_k A_{ki} A_{kj}, \qquad w_i \;=\; \sum_k m_k A_{ki}, \qquad m_{\mathrm{tot}} \;=\; \sum_k m_k . \]2 Swing-phase dynamics
The pinned Euler-Lagrange equations are
\[ D(q)\,\ddot q + C(q,\dot q)\,\dot q + G(q) \;=\; B\,u, \]with, for the lumped-tree construction above,
\[ D_{ij}(q) \;=\; B^c_{ij}\cos(q_i - q_j) \;+\; \delta_{ij} I_i, \qquad \big(C\dot q\big)_i \;=\; \sum_j B^c_{ij}\,\sin(q_i - q_j)\,\dot q_j^{\,2}, \] \[ G_i(q) \;=\; -\,g_0\, w_i \sin(q_i + \alpha), \]where \(I_i\) are link rotational inertias and \(B\) maps actuator torques to generalized forces (each internal torque appears with opposite signs on the two links it couples). These expressions follow directly from the Lagrangian of the lumped tree: the kinetic energy \( T = \tfrac12 \sum_k m_k |\dot c_k|^2 + \tfrac12 \sum_j I_j \dot q_j^2 \) yields \(D\) and the centrifugal terms, and the potential \( V = \sum_k m_k\, g_0\, (\cos\alpha\; c_k^y - \sin\alpha\; c_k^x) \) yields \(G\); the absolute-angle parametrization is what reduces the Coriolis matrix to the single-sum centrifugal form shown. As the anchor validation, this general tree construction reproduces an independently derived closed-form three-link model term by term, with zero numerical error. Integration is fixed-step RK4 with the controller re-evaluated per stage, except that user controllers run on a zero-order hold over each step, matching how a discrete controller acts on a real machine. Total mechanical energy in the tilted frame,
\[ E \;=\; \tfrac12 \dot q^{\mathsf T} D(q)\, \dot q \;+\; g_0\Big[\cos\alpha \sum_j w_j \cos q_j \;-\; \sin\alpha\big(m_{\mathrm{tot}}\, x_b + \sum_j w_j \sin q_j\big)\Big], \]drifts by less than \(10^{-11}\) over seconds of passive swing.
3 Rigid impact and relabeling
Swing-foot touchdown is an instantaneous inelastic impact. Extend the coordinates with the stance-base position, \(q_e = (q;\, p_e)\), and form the extended inertia matrix \(D_e\), whose base-coupling blocks are the columns \(w_i\, u'(q_i)\). Integrating the dynamics over the impact instant, all finite forces vanish and only the contact impulse \(F_2\) at the impacting foot survives, giving the impulsive momentum balance \( D_e(\dot q_e^{+} - \dot q_e^{-}) = E_2^{\mathsf T} F_2 \) with \(E_2 = \partial p_2 / \partial q_e\) the Jacobian of the impacting foot. Closing the system with the inelastic contact condition \(E_2\, \dot q_e^{+} = 0\), the post-impact velocity and impulse solve the block system
\[ \begin{bmatrix} D_e & -E_2^{\mathsf T} \\ E_2 & 0 \end{bmatrix} \begin{bmatrix} \dot q_e^{+} \\ F_2 \end{bmatrix} = \begin{bmatrix} D_e\, \dot q_e^{-} \\ 0 \end{bmatrix}, \]followed by the leg-relabeling permutation. The rigid contact model is only self-consistent under conditions that must be checked rather than assumed, and the simulator checks all three at every impact: normal impulse \(F_{2}^{N} > 0\), friction cone \(|F_2^{T}| \le \mu F_2^{N}\), and former-stance-foot liftoff \(\dot p_1^{v+} \ge 0\); the instrument lamps display all three. When the pre-impact stance is sliding (Section 9), the right-hand side carries the base momentum: \( \dot q_e^- \) includes \(v_b\) in its base slot, adding \(w_i \cos(q_i)\, v_b\) to the angular rows and \(m_{\mathrm{tot}} v_b\) to the horizontal row. Angular momentum about the new contact point is conserved through the impact map to relative error below \(10^{-15}\).
4 The footed humanoid hybrid
The footed Unitree G1 alternates two continuous phases joined by two transitions, the structure of a hybrid system with impulse effects:
\[ \Sigma:\; \begin{cases} \dot x_a = f_a(x_a) + g_a(x_a)\, u_a, & x_a \notin S_a^u,\\[2pt] x_u^{+} = \Delta_a^u(x_a^{-}), & x_a^{-} \in S_a^u \quad (\text{heel rise}),\\[2pt] \dot x_u = f_u(x_u) + g_u(x_u)\, u_u, & x_u \notin S_u^a,\\[2pt] x_a^{+} = \Delta_u^a(x_u^{-}), & x_u^{-} \in S_u^a \quad (\text{flat-foot impact}). \end{cases} \]Phase a (flat foot). The stance foot is flat and pinned: 9 coordinates, 9 torques, fully actuated, with the chain anchored above the stance ankle. Phase u (toe roll). The heel has risen and the foot rotates about the passive toe: 10 coordinates with the stance-foot angle appended last, one degree of underactuation. Heel rise is a control decision triggered at a prescribed value of the monotone gait phase \(s(q)\); positions and velocities are continuous across it (a coordinate re-embedding, not an impact), and the simulator conserves total energy across this transition exactly, to the last floating-point digit. Touchdown uses an 11-coordinate freed-foot impact: the swing foot strikes flat, the impact solve locks the foot orientation (lock index 10), and the returned impulse moment resolves into the foot-slap moment and the center of pressure, whose location within the sole is monitored as the CoP validity check. The toe sits 12 cm ahead of the ankle, so honest stride metrics account for the base shift from ankle to toe at heel rise.
5 Virtual constraints and feedback linearization
Within-stride control follows the virtual-constraint philosophy. Choose outputs
\[ y \;=\; h(q) \;=\; h_0(q) - h_d\big(s(q)\big), \]where \(h_0\) selects controlled combinations of coordinates and \(h_d\) is their desired evolution along a strictly monotone phase variable \(s(q)\), replacing time. Differentiating twice along the dynamics,
\[ \ddot y \;=\; \underbrace{J_h\, D^{-1}\big(-C\dot q - G\big) + \dot J_h\, \dot q}_{F(q,\dot q)} \;+\; \underbrace{J_h\, D^{-1} B}_{A(q)}\, u , \qquad J_h = \frac{\partial h}{\partial q}, \]and the reference computed-torque law inverts the decoupling matrix,
\[ u \;=\; A^{-1}(q)\,\big(-F - k_p\, y - k_d\, \dot y\big), \]which presumes exact knowledge of \(F\). Everything in Section 6 exists to remove that presumption. The desired evolutions are smooth clearance and flexion shapes; the mirror constraint drives the swing leg as the reflection of the stance leg plus clearance, so the switching surface is reached transversally. The zero dynamics of each model are the internal dynamics on the constraint manifold \(\{y = 0,\ \dot y = 0\}\); their stride-to-stride behavior is summarized by the Poincare samples in the phase portrait.
6 Adaptive and learning control
All learning controllers use the error hierarchy
\[ e = y, \qquad r = \dot e + \Lambda e, \quad \Lambda > 0, \]and the known control effectiveness \(A(q)\), consistent with the standing assumption that the input-output effectiveness is known while the drift is not.
Adaptive integral. The simplest template augments FL-style feedback with an integral disturbance estimate per output channel, \(\hat d \leftarrow \hat d + \gamma\, r\, dt\), subtracted in the output dynamics. It compensates constant offsets (payloads, actuator bias) and is the pedagogical bridge to the two laws below.
LbDNN switching adaptive controller. Each continuous phase \(p \in \{a, u\}\) of the humanoid carries its own deep network \(\Phi_p(x;\hat\vartheta_p)\) approximating that phase's drift \(F_p\), its own gains, and its own adaptation; the shape law implemented is
\[ u_p \;=\; A_p^{-1}\Big( -\Phi_p(x;\hat\vartheta_p) - \Lambda \dot y - k_r\, r - e - \delta_{pa}\, A_{a2}\, u_A \Big), \]with the ankle cross-coupling \(A_{a2} u_A\) cancelled exactly in the fully actuated phase so the phase-scheduled ankle policy \(u_A(s)\) acts on the reduced dynamics alone. The weight update is the Jacobian-transpose gradient law with sigma modification,
\[ \dot{\hat\vartheta}_p \;=\; \Gamma_p\Big( \Phi_p'(x;\hat\vartheta_p)^{\mathsf T} r \;-\; \sigma\, \hat\vartheta_p \Big), \]integrated at the simulation step, which is the direct implementation of the Lyapunov-based all-layer adaptation of the accompanying theory with the smooth projection replaced by the sigma leak (the boundedness mechanism the leak provides is the one the projection certifies; the simulator states this simplification rather than hiding it). The transport rule is the essential hybrid ingredient: when a phase is inactive its network is frozen, so each network accumulates learning across the recurrences of its own phase and the weight error is continuous across the other phase. Under the theory, the closed loop converges to a neighborhood of the design orbit whose radius separates into a network reconstruction term, a gain-suppressed residual weight-error term, and a transition-mismatch floor that no within-phase learning can remove.
RISE. The Robust Integral of the Sign of the Error replaces model knowledge of the drift with a robust integral. With \(r = \dot y + \Lambda_1 y\), the implemented law is
\[ u \;=\; A^{-1} v, \qquad v \;=\; -(K_s + 1)\big(r - r(0)\big) \;-\; \nu, \qquad \dot\nu \;=\; (K_s+1)\,\Lambda_2\, r \;+\; \beta\, \mathrm{sgn}(r). \]For disturbances with bounded first derivatives, RISE recovers asymptotic tracking where UUB designs keep a residual; the smoothed Coulomb friction field of Section 9 lies exactly in this class. In the hybrid tube constants of the stride-to-stride analysis, RISE attacks the within-phase disturbance terms \(d_p / (2 a_p)\) while the transition floors \(\beta_a, \beta_u\) are untouched. Two honest caveats. Each stance phase has finite duration, so the asymptotic limit is never reached within a stride; the working claim is a much smaller effective residual. And the integrator state must cross the resets under some transport rule; here it persists across strides, the analog of the weight-transport rule, and the stride-to-stride theory of integrator transport through resets is, to our knowledge, open.
LbDNN + RISE composite. The humanoid composite runs per-mode robust integrals \(\nu_a, \nu_u\) alongside the per-mode networks, transported frozen by the same rule, with the leaky update
\[ \dot\nu_p \;=\; k_1\, r \;+\; \beta\, \mathrm{sgn}(r) \;-\; k_{\mathrm{leak}}\, \nu_p . \]The leak is not cosmetic: impact re-excitation of \(r\) otherwise winds the integral up stride after stride until the gait destabilizes, a live instance of the open transport problem. The leak bounds the windup at the price of the asymptotic claim, and the network absorbs the repeatable drift while the integral sweeps the remainder.
7 Safety filtering
The CBF templates filter any nominal torque through exponential control barrier functions. For a constraint \(h(q) \ge 0\) of relative degree two, the ECBF condition along the output dynamics is
\[ \ddot h \;+\; K_1\, \dot h \;+\; K_2\, h \;\ge\; 0, \]imposed pointwise on \(u\) together with the torque box, via an alternating projection onto the affine constraint set (an approximate QP adequate at the control rate). The pole condition matters in practice: the ECBF poles must be faster than the nominal loop bandwidth, otherwise the filter blocks the very decelerations feedback linearization needs and destabilizes the gait it is guarding. The humanoid filter combines the torso barrier with the CoP condition of Section 4.
8 Neural policy runner
The policy runner executes networks imported as JSON: dense layers \(a \mapsto \varsigma(W^{\mathsf T} a + b)\) with tanh, ReLU, or ELU activations, optionally preceded by an LSTM block in PyTorch gate order,
\[ \begin{aligned} & g = W_{ih}^{\mathsf T} x + b_{ih} + W_{hh}^{\mathsf T} h + b_{hh}, \qquad g = [\,g_i;\ g_f;\ g_c;\ g_o\,],\\[2pt] & c^{+} = \sigma(g_f) \odot c + \sigma(g_i) \odot \tanh(g_c), \qquad h^{+} = \sigma(g_o) \odot \tanh(c^{+}), \end{aligned} \]with the recurrent state carried in the controller memory and reset on apply. The runner is verified to numerical parity, at the \(10^{-5}\) level set by six-decimal weight rounding, against Unitree's official pre-trained G1, H1, and H1-2 deployment policies over recurrent rollouts. Those policies expect their own observation and action contracts, stated in each converted file; an adapter between embodiments is user code, and the embodiment gap between a 3D position-target policy and this planar torque-controlled reduction is real and stated.
9 Dynamic environments
All environment effects act on the true plant only; controllers never see them.
Joint friction. Joint rates follow from actuator duality, \(\dot q_J = B^{\mathsf T} \dot q\). Each actuated joint receives Coulomb friction with a Stribeck knee plus viscous drag,
\[ f_j \;=\; -\Big( F_c \big[ 1 + \kappa\, e^{-\dot q_{J,j}^2 / v_s^2} \big]\, \tanh\!\big(\dot q_{J,j} / \epsilon\big) \;+\; F_v\, \dot q_{J,j} \Big), \]mapped back as the generalized force \(\tau_{\mathrm{ext}} = B f\), with \(\kappa = 0.5\), \(v_s = 0.1\), \(\epsilon = 0.02\). The smoothing makes the field a stiff but C-one drift term, the class RISE assumes, and the field is verified dissipative.
Stick-slip ground contact. In stick, the pin is rigid and the ground reaction is monitored from the momentum balances,
\[ F_N = m_{\mathrm{tot}}\, g_0 \cos\alpha + \sum_j w_j\big(-\sin(q_j)\,\ddot q_j - \cos(q_j)\,\dot q_j^2\big), \] \[ F_T = \sum_j w_j\big(\cos(q_j)\,\ddot q_j - \sin(q_j)\,\dot q_j^2\big) - m_{\mathrm{tot}}\, g_0 \sin\alpha . \]Slip begins when \(|F_T| > \mu F_N\); liftoff \(F_N \le 0\) is outside the pinned model class and is flagged as a fall. During slip the base abscissa becomes a coordinate and the sliding system solves accelerations, base slide, and normal force simultaneously,
\[ \begin{bmatrix} D(q) & w \circ \cos q & 0 \\ (w \circ \cos q)^{\mathsf T} & m_{\mathrm{tot}} & \mu\, s_0 \\ (w \circ \sin q)^{\mathsf T} & 0 & 1 \end{bmatrix} \begin{bmatrix} \ddot q \\ a_b \\ F_N \end{bmatrix} = \begin{bmatrix} Bu - C\dot q - G + \tau_{\mathrm{ext}} \\ m_{\mathrm{tot}}\, g_0 \sin\alpha + \sum_j w_j \sin(q_j)\, \dot q_j^2 \\ m_{\mathrm{tot}}\, g_0 \cos\alpha - \sum_j w_j \cos(q_j)\, \dot q_j^2 \end{bmatrix}, \]with \(s_0 = \mathrm{sgn}(v_b)\) and kinetic friction \(F_T = -\mu\, s_0\, F_N\). Re-latch occurs at a zero crossing of \(v_b\) whose stick force is feasible. The energy identity \(\tfrac{d}{dt}\big(E + W_f\big) = P_{\mathrm{act}}\) with friction work \(\dot W_f = \mu F_N |v_b|\) closes to \(10^{-8}\) in the test suite, where the sliding kinetic energy includes the base terms \(v_b \sum_j w_j \cos(q_j)\dot q_j + \tfrac12 m_{\mathrm{tot}} v_b^2\). Ice patches reschedule \(\mu\) per stance. The reaction guards arm after the first stride because the initial computed-torque transient demands contact forces the rigid-pin idealization supplies silently. Stick-slip is implemented for the single-phase pinned models; the footed humanoid reports impact-cone utilization at touchdown.
Trips. An obstacle strike is a Cartesian impulse \(\hat F\) at the swing foot, mapped exactly through the swing-foot Jacobian,
\[ \Delta\dot q \;=\; D^{-1}(q)\, J_{\mathrm{sw}}^{\mathsf T}\, \hat F, \]verified by the angular-momentum identity \(\Delta H_{\mathrm{base}} = p_{\mathrm{sw}} \times \hat F\) to \(10^{-14}\); the residual moment about the strike point is the pin reaction, as it must be.
10 Model mismatch architecture
The simulator maintains a design model and a true plant. User controllers receive the design model through their context; the integrator runs the true plant, constructed by scaling masses and inertias, adding payloads at the heaviest link, and mapping torques through actuator effectiveness and bias, \(u_{\mathrm{true}} = \eta\, u + b\). Built-in controllers are served the design model through the same mechanism, so exact-model and learned controllers face the same reality gap. This is the experimental separation the adaptive theory needs: the drift the network learns is the true one, the effectiveness the law inverts is the nominal one.
11 Metrics and batch evaluation
Tracking quality is the exponential moving mean of the squared outputs, \(\overline{|y|^2}\), reported per controller. Stride metrics include length, duration, speed, impact impulse, cone utilization, slip per stride, and dissipated friction work. Batch evaluation draws Monte Carlo mismatch samples, runs the scheduled disturbance protocols, and reports the fall rate plus a contraction estimate: the leading Poincare-map eigenvalue is estimated from successive post-impact samples by least squares on \(\|x_{k+1} - x^\ast\| \approx \rho\, \|x_k - x^\ast\|\), the empirical analog of the stride-to-stride contraction factor of the hybrid stability analysis.
12 Validation and limitations
Anchor validations, all reproduced in the shipped regression suites: the general tree construction against an independently derived closed-form three-link model, error \(0.00 \times 10^{0}\); passive energy drift below \(10^{-11}\) over seconds; impact momentum bookkeeping to \(10^{-15}\) relative; heel-rise energy continuity exact to the last digit; foot-slap moment equal to the angular momentum change about the contact to machine precision; slip energy audit to \(10^{-8}\); trip momentum to \(10^{-14}\); policy-runner parity with official pre-trained weights at \(10^{-5}\).
Limitations, stated plainly. The models are planar; lateral dynamics and yaw are absent. Feet are rigid and the swing foot has no dorsiflexion, which is the documented source of the humanoid's push fragility; recovery by step placement is not implemented, so chained short steps are unrecoverable by design honesty rather than by accident. Ground compliance is not modeled. Stick-slip is single-phase only. The RISE integrator transport across resets lacks a stride-to-stride theory; the leaky implementation trades the asymptotic claim for boundedness. Liftoff terminates the pinned model class rather than starting a flight phase.